package com.hl.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.mapper.FieldMapper;
import com.hl.pojo.Expertiseareas;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FieldServiceImpl implements FieldService {
//    mapper依赖注入
    @Resource
    private FieldMapper fieldMapper;
//    查询所有
    @Override
    public PageInfo getFieldList(Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Expertiseareas> fieldList = fieldMapper.queryFieldList();
        PageInfo<Expertiseareas> fieldPageInfo = new PageInfo<>(fieldList);
        return fieldPageInfo;
    }
    //    根据name模糊查询
    @Override
    public List<Expertiseareas> likeGetByName(String name) {
        List<Expertiseareas> fields = fieldMapper.likeQueryByName(name);
        return fields;
    }

    @Override
    public String addField(Expertiseareas expertiseareas) {
        int affect = fieldMapper.addField(expertiseareas);
        String s = affect == 1 ? "添加成功" : "添加失败";
        return s;
    }

    @Override
    public String updateField(Expertiseareas expertiseareas) {
        int affect = fieldMapper.updateField(expertiseareas);
        String s = affect == 1 ? "修改成功" : "修改失败";
        return s;
    }

    @Override
    public String deleteField(Integer id) {
        int affect = fieldMapper.deleteField(id);
        String s = affect == 1 ? "删除成功" : "删除失败";
        return s;
    }

}
